{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import tensorflow as tf\n",
    "\n",
    "@tf.function\n",
    "def np_random():\n",
    "    a = np.random.randn(3,3)\n",
    "    tf.print(a)\n",
    "\n",
    "@tf.function\n",
    "def tf_random():\n",
    "    a = tf.random.normal((3,3,))\n",
    "    tf.print(a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "array([[-0.37502673, -0.92321499, -1.40326383],\n",
      "       [ 0.06518075, -2.53411197,  0.70439073],\n",
      "       [-0.89859416,  0.25204324, -1.13377055]])\r\n",
      "array([[-0.37502673, -0.92321499, -1.40326383],\n",
      "       [ 0.06518075, -2.53411197,  0.70439073],\n",
      "       [-0.89859416,  0.25204324, -1.13377055]])\r\n"
     ]
    }
   ],
   "source": [
    "np_random()\n",
    "np_random()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.405774236 2.33346987 0.296058595]\n",
      " [-0.789594769 -0.479724705 -0.415866226]\n",
      " [-0.68194288 0.0271834712 -1.11628878]]\r\n",
      "[[-1.58073878 0.514521062 -1.40236437]\n",
      " [-0.333607972 0.152493536 -2.27009416]\n",
      " [0.973719597 0.584458 -0.211536467]]\r\n"
     ]
    }
   ],
   "source": [
    "tf_random()\n",
    "tf_random()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\r\n",
      "3\r\n"
     ]
    },
    {
     "data": {
      "text/plain": "<tf.Tensor: shape=(), dtype=float32, numpy=3.0>"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = tf.Variable(1.0,dtype=tf.float32)\n",
    "@tf.function\n",
    "def outer_var():\n",
    "    x.assign_add(1.0)\n",
    "    tf.print(x)\n",
    "    return x\n",
    "outer_var()\n",
    "outer_var()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[<tf.Tensor 'x:0' shape=() dtype=float32>]\n"
     ]
    }
   ],
   "source": [
    "tensor_list = []\n",
    "\n",
    "@tf.function\n",
    "def append_tensor(x):\n",
    "    tensor_list.append(x)\n",
    "    return tensor_list\n",
    "\n",
    "append_tensor(tf.constant(5.0))\n",
    "append_tensor(tf.constant(6.0))\n",
    "print(tensor_list)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}